package com.ucs.ui;

import com.ucs.domain.Category;
import com.ucs.domain.Item;
import com.ucs.util.UCSData;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;

public class SelectCategoryItemListActivity extends ExpandableListActivity{
	public static final String ITEM = "Item";
	private ExpandableListAdapter ela;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ela = new CategoryItemListAdaptor();        
		setListAdapter(ela); 
		
	}
	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		Category category = UCSData.getInstance().getCategories().get(groupPosition);
		Item item = category.getItems().get(childPosition);
		Bundle bundle = new Bundle();
		bundle.putSerializable(SelectCategoryItemListActivity.ITEM, item);
//		bundle.putSerializable(SelectCategoryItemListActivity.CATEGORY, category);
		Intent intent = new Intent();
		intent.putExtras(bundle);
		setResult(RESULT_OK, intent);
		finish();		
		return true;
	}
}
